//
//  ComplainDetailController.m
//  PropertyMananger
//
//  Created by bh on 17/1/17.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "ComplainDetailController.h"
#import "RepairDetailCell.h"
#import "DescribeCell.h"
#import "ComplainDetailStateCell.h"

@interface ComplainDetailController ()

@end

@implementation ComplainDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initTableViewWithView:self.view frame:CGRectMake(0, 0, BHscreenW, BHscreenH - 64) isGroup:NO];
    self.tableView.backgroundColor = BHColor(238, 238, 238);
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self initTitleViewName:@"投诉详情"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([self.model.ComplaintsProcessState isEqualToString:@"10"] || [self.model.ComplaintsProcessState isEqualToString:@"20"]) {
        
        return 8;
        
    }else{
        
        return 9;
    }

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RepairDetailCell * cell = [RepairDetailCell cellWithTableView:tableView];
    if (indexPath.row == 0) {
        
        self.titleStr = @"投诉编号:";
        self.pingjieStr = [NSString stringWithFormat:@"%@  %@",self.titleStr,self.model.ComplaintCode];
        DLog(@"上一级传过来的投诉单编号 === %@",self.model.ComplaintCode);
        self.stra = [[NSMutableAttributedString alloc]initWithString:self.pingjieStr];//可随意拼接字符串
        [self.stra addAttributes:@{NSFontAttributeName:BHFont(15),NSForegroundColorAttributeName:BHColor(102, 102, 102)} range:NSMakeRange(0, self.titleStr.length)];
        cell.infoLabel.attributedText = self.stra;
        
    }else if (indexPath.row == 1){
        
        self.titleStr = @"投诉人:";
        self.pingjieStr = [NSString stringWithFormat:@"%@ %@",self.titleStr,self.model.ComplaintMan];
        
        self.stra = [[NSMutableAttributedString alloc]initWithString:self.pingjieStr];//可随意拼接字符串
        [self.stra addAttributes:@{NSFontAttributeName:BHFont(15),NSForegroundColorAttributeName:BHColor(102, 102, 102)} range:NSMakeRange(0, self.titleStr.length)];
        cell.infoLabel.attributedText = self.stra;
        
    }else if (indexPath.row == 2){
        self.titleStr = @"投诉人电话:";
        if (self.model.ComplaintManTel == nil) {
            
         self.pingjieStr = [NSString stringWithFormat:@"%@  %@",self.titleStr,@""];
        }else{
        
            [cell.phoneBtn setImage:IMG(@"ico_dial_telephone") forState:UIControlStateNormal];
            [cell.phoneBtn addTarget:self action:@selector(phoneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            
             self.pingjieStr = [NSString stringWithFormat:@"%@  %@",self.titleStr,self.model.ComplaintManTel];
        
        }
       
        
        self.stra = [[NSMutableAttributedString alloc]initWithString:self.pingjieStr];//可随意拼接字符串
        [self.stra addAttributes:@{NSFontAttributeName:BHFont(15),NSForegroundColorAttributeName:BHColor(102, 102, 102)} range:NSMakeRange(0, self.titleStr.length)];
        cell.infoLabel.attributedText = self.stra;
        
    }else if (indexPath.row == 3){
        
        self.titleStr = @"投诉方式:";
        if (self.model.ComplaintsWayValue == nil) {
            
            self.pingjieStr = [NSString stringWithFormat:@"%@  %@",self.titleStr,@""];
        }else{
        self.pingjieStr = [NSString stringWithFormat:@"%@  %@",self.titleStr,self.model.ComplaintsWayValue];
        }
        
        
        self.stra = [[NSMutableAttributedString alloc]initWithString:self.pingjieStr];//可随意拼接字符串
        [self.stra addAttributes:@{NSFontAttributeName:BHFont(15),NSForegroundColorAttributeName:BHColor(102, 102, 102)} range:NSMakeRange(0, self.titleStr.length)];
        cell.infoLabel.attributedText = self.stra;
        
    }else if (indexPath.row == 4){
        self.titleStr = @"投诉程度:";
        if (self.model.ComplaintsDegreeValue == nil) {
            
            self.pingjieStr = [NSString stringWithFormat:@"%@  %@",self.titleStr,@""];
        }else{
            self.pingjieStr = [NSString stringWithFormat:@"%@  %@",self.titleStr,self.model.ComplaintsDegreeValue];
        }
        
        cell.infoLabel.textColor = [UIColor redColor];
        self.stra = [[NSMutableAttributedString alloc]initWithString:self.pingjieStr];//可随意拼接字符串
        [self.stra addAttributes:@{NSFontAttributeName:BHFont(15),NSForegroundColorAttributeName:BHColor(102, 102, 102)} range:NSMakeRange(0, self.titleStr.length)];
        cell.infoLabel.attributedText = self.stra;
        
    }else if (indexPath.row == 5){
        
        self.titleStr = @"投诉时间:";
        self.pingjieStr = [NSString stringWithFormat:@"%@  %@",self.titleStr,self.model.ComplaintTime];
        
        self.stra = [[NSMutableAttributedString alloc]initWithString:self.pingjieStr];//可随意拼接字符串
        [self.stra addAttributes:@{NSFontAttributeName:BHFont(15),NSForegroundColorAttributeName:BHColor(102, 102, 102)} range:NSMakeRange(0, self.titleStr.length)];
        cell.infoLabel.attributedText = self.stra;
        
    }else if (indexPath.row == 6){
        
        DescribeCell * cell = [DescribeCell cellWithTableView:tableView];
        
        cell.titleLabel.text = @"投诉内容";
        cell.infoLabel.text = self.model.Contents;
        
        return cell;
        
        
    }else if (indexPath.row == 7){
        
        if ([self.model.ComplaintsProcessState isEqualToString:@"10"] || [self.model.ComplaintsProcessState isEqualToString:@"20"]) {
            
            ComplainDetailStateCell * orderDetailCell = [ComplainDetailStateCell cellWithTableView:tableView];
            orderDetailCell.processState = self.model.ComplaintsProcessState;
            return orderDetailCell;
        
        }else{
            
            DescribeCell * cell = [DescribeCell cellWithTableView:tableView];
            
            cell.titleLabel.text = @"处理结果";
            
            cell.infoLabel.text = self.model.ReplyContent;
            
            return cell;
        }
        
        
    }else if (indexPath.row == 8){
        
        ComplainDetailStateCell * orderDetailCell = [ComplainDetailStateCell cellWithTableView:tableView];
        orderDetailCell.processState = self.model.ComplaintsProcessState;
        return orderDetailCell;
        
    }
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 6) {
        
        return [DescribeCell cellComplainDescQuestionHeightWiht:self.model];
        
    }else if (indexPath.row == 7){
        
        if ([self.model.ComplaintsProcessState isEqualToString:@"10"] || [self.model.ComplaintsProcessState isEqualToString:@"20"]) {
            
            return 90;
        }else{
            
            return [DescribeCell cellWorkComplainReplyResultHeightWiht:self.model];
        }
        
    }else if (indexPath.row == 8){
        
        return 90;
        
    }else{
        
        return 50;
    }
    
}
#pragma mark - 点击打电话
- (void)phoneBtnClick:(UIButton *)button{
    
    DLog(@"点击了 电话");
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",self.model.ComplaintManTel];
    UIWebView * callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self.view addSubview:callWebview];
}
@end
